function [b2w, w2b, line_edge_num] = cal_edge(image_in,image_height,image_width)
%% notes
%{
function: cal_edge
describe: Transform the BW image to edge image
author: Yixu Chen
sample:[b2w, w2b, line_edg_num] = cal_edge('fire49.bmp');
note: 
    1.same value between b2w and w2b in same position means 101/010 in picture
    2.in the image read, the 0 repsent Black and 1 repsent White
%}
%% user defined constant
max_edge = 10;
%% function body
% add two sides' coloums as black
image_lr_add_k = [zeros(image_height,1) image_in zeros(image_height,1)];

%initialization
num_edge = 1;
b2w = zeros(image_height, max_edge, 'uint8');
w2b = zeros(image_height, max_edge, 'uint8');
line_edge_num = zeros(image_height,1, 'uint8');
%calulate edge
for i = 1:image_height %from top to bottom
    for j = 2:image_width+2 % 2~82
        if image_lr_add_k(i, j-1) == 0 && image_lr_add_k(i,j) == 1
            b2w(i, num_edge) = j - 1;            
        end
        if image_lr_add_k(i, j-1) == 1 && image_lr_add_k(i,j) == 0
            w2b(i, num_edge) = j - 2;
            num_edge = num_edge + 1;
        end
        if num_edge >= max_edge + 1 % if edges number out of max_edge
            warning('edges number out of max_edge');
            break; % ignore later edges
        end
    end
    line_edge_num(i,1) = num_edge - 1;
    num_edge = 1;
end
end